<?php

/*
 * This file is part of the php-phantomjs.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace lemon\phantomjs\Tests\Unit;

use lemon\phantomjs\Client;
use lemon\phantomjs\Engine;
use lemon\phantomjs\Http\MessageFactoryInterface;
use lemon\phantomjs\Procedure\ProcedureLoaderInterface;
use lemon\phantomjs\Procedure\ProcedureCompilerInterface;

/**
 * PHP PhantomJs
 *
 * @author Jon Wenmoth <contact@jonnyw.me>
 */
class ClientTest extends \PHPUnit_Framework_TestCase
{

/** +++++++++++++++++++++++++++++++++++ **/
/** ++++++++++++++ TESTS ++++++++++++++ **/
/** +++++++++++++++++++++++++++++++++++ **/

	/**
	 * Test can get client through
	 * factory method.
	 *
	 * @access public
	 * @return void
	 */
	public function testCanGetClientThroughFactoryMethod(){
		$this->assertInstanceOf('\lemon\phantomjs\Client', Client::getInstance());
	}

	/**
	 * Test can get engine.
	 *
	 * @return void
	 */
	public function testCanGetEngne(){
		$engine			 = $this->getEngine();
		$procedureLoader	= $this->getProcedureLoader();
		$procedureCompiler  = $this->getProcedureCompiler();
		$messageFactory	 = $this->getMessageFactory();

		$client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory);

		$this->assertInstanceOf('\lemon\phantomjs\Engine', $client->getEngine());
	}

	/**
	 * Test can get message factory
	 *
	 * @return void
	 */
	public function testCanGetMessageFactory(){
		$engine			 = $this->getEngine();
		$procedureLoader	= $this->getProcedureLoader();
		$procedureCompiler  = $this->getProcedureCompiler();
		$messageFactory	 = $this->getMessageFactory();

		$client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory);

		$this->assertInstanceOf('\lemon\phantomjs\Http\MessageFactoryInterface', $client->getMessageFactory());
	}

	/**
	 * Test can get procedure loader.
	 *
	 * @return void
	 */
	public function testCanGetProcedureLoader(){
		$engine			 = $this->getEngine();
		$procedureLoader	= $this->getProcedureLoader();
		$procedureCompiler  = $this->getProcedureCompiler();
		$messageFactory	 = $this->getMessageFactory();

		$client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory);

		$this->assertInstanceOf('\lemon\phantomjs\Procedure\ProcedureLoaderInterface', $client->getProcedureLoader());
	}

/** +++++++++++++++++++++++++++++++++++ **/
/** ++++++++++ TEST ENTITIES ++++++++++ **/
/** +++++++++++++++++++++++++++++++++++ **/

	/**
	 * Get client instance
	 *
	 * @param  \lemon\phantomjs\Engine							   $engine
	 * @param  \lemon\phantomjs\Procedure\ProcedureLoaderInterface   $procedureLoader
	 * @param  \lemon\phantomjs\Procedure\ProcedureCompilerInterface $procedureCompiler
	 * @param  \lemon\phantomjs\Http\MessageFactoryInterface		 $messageFactory
	 * @return \lemon\phantomjs\Client
	 */
	protected function getClient(Engine $engine, ProcedureLoaderInterface $procedureLoader, ProcedureCompilerInterface $procedureCompiler, MessageFactoryInterface $messageFactory){
		$client = new Client($engine, $procedureLoader, $procedureCompiler, $messageFactory);

		return $client;
	}

/** +++++++++++++++++++++++++++++++++++ **/
/** ++++++++++ MOCKS / STUBS ++++++++++ **/
/** +++++++++++++++++++++++++++++++++++ **/

	/**
	 * Get engine
	 *
	 * @access protected
	 * @return \lemon\phantomjs\Engine
	 */
	protected function getEngine(){
		$engine = $this->getMock('\lemon\phantomjs\Engine');

		return $engine;
	}

	/**
	 * Get message factory
	 *
	 * @access protected
	 * @return \lemon\phantomjs\Http\MessageFactoryInterface
	 */
	protected function getMessageFactory(){
		$messageFactory = $this->getMock('\lemon\phantomjs\Http\MessageFactoryInterface');

		return $messageFactory;
	}

	/**
	 * Get procedure loader.
	 *
	 * @access protected
	 * @return \lemon\phantomjs\Procedure\ProcedureLoaderInterface
	 */
	protected function getProcedureLoader(){
		$procedureLoader = $this->getMock('\lemon\phantomjs\Procedure\ProcedureLoaderInterface');

		return $procedureLoader;
	}

	/**
	 * Get procedure validator.
	 *
	 * @access protected
	 * @return \lemon\phantomjs\Procedure\ProcedureCompilerInterface
	 */
	protected function getProcedureCompiler(){
		$procedureCompiler = $this->getMock('\lemon\phantomjs\Procedure\ProcedureCompilerInterface');

		return $procedureCompiler;
	}
}
